#!/usr/bin/env node

import figlet from "figlet";
import chalk from "chalk";
import boxen from "boxen";
import { program } from "commander";
import { chatCommand } from "./commands/openai";

function initCLI() {
  const args = process.argv.slice(2); // 获取命令行参数

  if (args.length === 0) {
    // 如果没有命令行参数，显示欢迎信息
    welcomeShow();
  }

  showCommand();
  program.on("command:*", () => {
    process.exit(1);
  });
  // 解析命令行输入
  program.parse(process.argv);
}

function welcomeShow() {
  const title = figlet.textSync("Asuka", {
    font: "Standard",
    horizontalLayout: "default",
    verticalLayout: "default",
  });

  const boxedTitle = boxen(title, {
    padding: 1,
    margin: 1,
    borderColor: "cyan",
    borderStyle: "round",
  });

  console.log(chalk.cyanBright(boxedTitle));

  console.log(
    chalk.yellow("🎉 欢迎使用 ") +
      chalk.greenBright("Asuka CLI") +
      chalk.yellow(" —— 你的前端开发好助手\n")
  );

  console.log(chalk.blue("📦 当前版本: ") + chalk.white("v0.0.1"));
  console.log(chalk.blue("💡 使用帮助: ") + chalk.green("ask --help"));
  // 添加作者信息
  console.log(chalk.blue("👨‍💻 作者: ") + chalk.white("Hor1z0n"));
}

async function showCommand() {
  program.addCommand(chatCommand());
}

// CLI 入口
initCLI();
